<?php

namespace app\admin\model;

use think\Db;
use think\Model;
use my\Security;
use app\admin\model\AdminModel;

class DriverModel extends Model
{
    protected $map = array();
    public function __construct()
    {
        parent::__construct();
        $areaInfo = AdminModel::getRoleArea();
        if(!empty($areaInfo)){
            $this->map['c.work_city'] = ['in',implode(',',$areaInfo['city'])];
        }
    }

    public function getDriverList($page, $limit, $data = array(), $field = '*', $export = '')
    {
        $where = $this->map;
        if (!empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['between', [strtotime($data['start']), strtotime($data['end'] . " 23:59:59")]];
        } elseif (!empty($data['start']) && empty($data['end'])) {
            $timeWhere = ['>=', strtotime($data['start'])];
        } elseif (empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['<=', strtotime($data['end'] . " 23:59:59")];
        }
        //注册时间
        if (!empty($data['type']) && $data['type'] == 1 && !empty($timeWhere)) {
            $where['register_time'] = $timeWhere;
        }
        //司机状态搜索
        //查询该司机是否在白名单 - 测试名单内
        $whiteList = Db::name('white_list')->order('id desc')->find();
        if (!empty($data['all_phone'])) {
            if ($data['all_phone'] == 1 && !empty($whiteList['driver_str'])) {        //正式司机
                $where['a.driver_id'] = ['not in', $whiteList['driver_str']];
            } elseif ($data['all_phone'] == 2 && !empty($whiteList['driver_str'])) {   //测试司机
                $where['a.driver_id'] = ['in', $whiteList['driver_str']];
            }
        }
        //登录时间
        if (!empty($data['type']) && $data['type'] == 2 && !empty($timeWhere)) {
            $where['last_login_time'] = $timeWhere;
        }

        //认证状态
        if ($data['auth_status'] != '') {
            $where['a.auth_status'] = $data['auth_status'];
        }
        //标签状态
        if (!empty($data['compliance_type'])) {
            $where['a.compliance_type'] = $data['compliance_type'];
        }
        //手机号码
        if ($data['driver_phone'] != '') {
            $where['a.driver_phone'] = Security::encrypt($data['driver_phone']);
        }
        //合规状态搜索
        if (!empty($data['confor_status'])) {
            $where['c.taxi_pass'] = $data['confor_status'];
            $where['c.taxi_certificate_pass'] = $data['confor_status'];
            $where['c.comm_pass'] = $data['confor_status'];
            $where['c.sail_pass'] = $data['confor_status'];
            $where['c.carriage_pass'] = $data['confor_status'];
        }
        //认证省市
        if (!empty($data['work_province'])) {
            $where['c.work_province'] = $data['work_province'];
        }
        if (!empty($data['work_city'])) {
            $where['c.work_city'] = $data['work_city'];
        }
        if ($data['referee_type'] != '') {
            if ($data['referee_type'] == 4) {
                $where['a.franchisee_type'] = 4;
            } elseif ($data['referee_type'] == 5) {
                $where['a.franchisee_type'] = 5;
            } else {
                $where['a.referee_type'] = $data['referee_type'];
                $referee_id = '';
                if($data['referee_type'] == 1){
                    //查询用户uid
                    $referee_id = Db::name('user')->where(['user_phone'=>Security::encrypt($data['refree_phone']),'false_status'=>0,'is_del'=>1])->value('uid');
                }elseif($data['referee_type'] == 2){
                    //查询司机driver_id
                    $referee_id = Db::name('driver_base')->where(['driver_phone'=>Security::encrypt($data['refree_phone'])])->value('driver_id');
                }
                if(!empty($referee_id)){
                    $where['a.referee_id'] = $referee_id;
                }
            }
        }
        if (session('admin_type') == 5 && session('franchisee_str') != '') {
            $where['a.franchisee_id'] = ['in', session('franchisee_str')];
        } else {
            if ($data['franchisee_info'] != '') {
                $where['a.franchisee_id'] = $data['franchisee_info'];
            }
        }
        //司机在线时长统计
        if (!empty($data['online_time']) && !empty($data['offline_time'])) {
            $onlineWhere['start_time'] = ['>=', strtotime($data['online_time'])];
            $onlineWhere['end_time'] = ['<=', strtotime($data['offline_time'] . " 23:59:59")];
        } elseif (!empty($data['online_time']) && empty($data['offline_time'])) {
            $onlineWhere['start_time'] = ['>=', strtotime($data['online_time'])];
        } elseif (empty($data['offline_time']) && !empty($data['offline_time'])) {
            $onlineWhere['end_time'] = ['<=', strtotime($data['offline_time'] . " 23:59:59")];
        } else {
            $onlineWhere['start_time'] = ['>=', strtotime(date("Y-m-d"))];
            $onlineWhere['end_time'] = ['<=', strtotime(date("Y-m-d") . " 23:59:59")];
        }
        //司机类型
        if (!empty($data['driver_type'])) {
            $where['a.driver_type'] = $data['driver_type'];
        }
        //根据司机driverId查询
         if(!empty($data['driverId'])) {
            $where['a.driver_id'] = $data['driverId'];
        }
        //标签信息
        $complianceInfo = config('compliance');
        //分页
        $start = ($page - 1) * $limit;
        $count = Db::name('driver_base a')->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')->
        join('car_info c', 'a.driver_id = c.driver_id', 'left')->where($where)->count();
        $list = Db::name('driver_base a')->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')->
        join('car_info c', 'a.driver_id = c.driver_id', 'left')->limit($start, $limit)->where($where)->field($field)->order('a.driver_id desc')->select();
        foreach ($list as $key => $value) {
            if (!empty($whiteList['driver_str']) && in_array($value['driver_id'], explode(',', $whiteList['driver_str']))) {
                $list[$key]['driver_type_status'] = 1;
            } else {
                $list[$key]['driver_type_status'] = 0;
            }
            $list[$key]['driver_phone'] = Security::decrypt($value['driver_phone']);
            $list[$key]['register_time'] = !empty($value['register_time']) ? date("Y-m-d H:i", $value['register_time']) : '-';
            $list[$key]['last_login_time'] = !empty($value['last_login_time']) ? date("Y-m-d H:i", $value['last_login_time']) : '-';
            //查询省市
            if (!empty($value['work_province']) && !empty($value['work_city'])) {
                $provinceName = Db::name('region')->where(['region_id' => $value['work_province']])->value('region_name');
                $cityName = Db::name('region')->where(['region_id' => $value['work_city']])->value('region_name');
                $list[$key]['provinceCity'] = $provinceName . ' / ' . $cityName;
            } else {
                $list[$key]['provinceCity'] = '-';
            }

            //认证状态
            if ($value['auth_status'] == 1) {
                $list[$key]['authStatusName'] = !empty($export) ? auth_status($value['auth_status']) : "<span style='color: green'>" . auth_status($value['auth_status']) . "</span>";
            } elseif ($value['auth_status'] == 3) {
                $list[$key]['authStatusName'] = !empty($export) ? auth_status($value['auth_status']) : "<span style='color: red'>" . auth_status($value['auth_status']) . "</span>";
            } else {
                $list[$key]['authStatusName'] = auth_status($value['auth_status']);
            }
            $list[$key]['complianceInfo'] = $value['auth_status'] == 1 ? $complianceInfo[$value['compliance_type']] : '-';
            //完成单数
            $list[$key]['orderNum'] = Db::name('order_common')->where('on_car_time', '>', $timeWhere[1][0])->where('on_car_time', '<', $timeWhere[1][1])->where(['order_status' => ['>=', 40], 'is_del' => 2, 'driver_id' => $value['driver_id']])->count();
            //收入
            if (!empty($data['type']) && $data['type'] == 3 && !empty($timeWhere)) {
                $money = Db::name('driver_wallet_record')->where(['record_type' => 1, 'driver_id' => $value['driver_id']])->where('time', $timeWhere)->value('SUM(money)');
            } else {
                $money = Db::name('driver_wallet_record')->where(['record_type' => 1, 'driver_id' => $value['driver_id']])->value('SUM(money)');
            }

            $list[$key]['money'] = sprintf("%.2f", $money / 100);
            //取消单数（乘客）
            /*if (!empty($data['type']) && $data['type'] == 3 && !empty($timeWhere)) {
                $list[$key]['cancelOrderUser'] = Db::name('order_common')->where(['order_status' => ['in', [12, 15]], 'is_del' => 2, 'driver_id' => $value['driver_id']])->where('order_time',$timeWhere)->count();
            }else{
                $list[$key]['cancelOrderUser'] = Db::name('order_common')->where(['order_status' => ['in', [12, 15]], 'is_del' => 2, 'driver_id' => $value['driver_id']])->count();
            }
            //取消单数（司机）
            if (!empty($data['type']) && $data['type'] == 3 && !empty($timeWhere)) {
                $list[$key]['cancelOrderDriver'] = Db::name('order_common')->where(['order_status' => 5, 'is_del' => 2, 'driver_id' => $value['driver_id']])->where('order_time',$timeWhere)->count();
            }else{
                $list[$key]['cancelOrderDriver'] = Db::name('order_common')->where(['order_status' => 5, 'is_del' => 2, 'driver_id' => $value['driver_id']])->count();
            }
            //罚款金额
            if (!empty($data['type']) && $data['type'] == 3 && !empty($timeWhere)) {
                $driver_fine = Db::name('order_common')->where(['order_status' => 5, 'is_del' => 2, 'driver_id' => $value['driver_id']])->where('order_time',$timeWhere)->value('SUM(driver_fine)');
            }else{
                $driver_fine = Db::name('order_common')->where(['order_status' => 5, 'is_del' => 2, 'driver_id' => $value['driver_id']])->value('SUM(driver_fine)');
            }
            $list[$key]['driverFineMoney'] = sprintf("%.2f", $driver_fine / 100);
            //投诉次数
            if (!empty($data['type']) && $data['type'] == 3 && !empty($timeWhere)) {
                $list[$key]['complaintNum'] = Db::name('complaint')->where('appeal_time',$timeWhere)->where(['driver_id' => $value['driver_id']])->count();
            }else{
                $list[$key]['complaintNum'] = Db::name('complaint')->where(['driver_id' => $value['driver_id']])->count();
            }*/
            //资料
            $is_supply = Db::name('driver_info_supplement')->where('driver_id', $value['driver_id'])->find();
            if ($is_supply) {
                $list[$key]['is_supplement'] = 1; //已补录
            } else {
                $list[$key]['is_supplement'] = 2; //未补录
            }
            //判断是否已封禁
            if ($value['forbid'] != 2) {
                $list[$key]['forbid'] = 1; //已封禁
            } else {
                $list[$key]['forbid'] = 2; //正常
            }
            //在线时长统计
            /*if (!empty($data['type']) && $data['type'] == 3 && !empty($timeWhere)) {
                $onlineTimeList = Db::name('driver_online_time')->where(['driver_id' => $value['driver_id']])->where('create_time', '>', $timeWhere[1][0])->where('create_time', '<', $timeWhere[1][1])->order('id desc')->select();
            } else {
                //查询累计司机在线时长
                $onlineTimeList = Db::name('driver_online_time')->where($onlineWhere)->where(['driver_id' => $value['driver_id']])->order('id desc')->select();
            }*/
            //如果是一条记录
            /*$timeCount = 0;
            $sum_time = 0;
            foreach ($onlineTimeList as $kly => $vmll) {
                if ($kly == 0 && empty($onlineTimeList[$kly]['end_time'])) {
                    $sum_time = time() - $vmll['start_time'];
                } else {
                    if (!empty($vmll['end_time'])) {
                        $sum_time = $vmll['end_time'] - $vmll['start_time'];
                    } else {
                        $sum_time = $onlineTimeList[$kly - 1]['start_time'] - $vmll['start_time'];
                    }
                }
                $timeCount += $sum_time;
            }
            $list[$key]['sum_time'] = get_second_h_m($timeCount);*/
            if (!empty($value['franchisee_type'])) {
                if ($value['franchisee_type'] == 4) {
                    $list[$key]['referee_type'] = '快车租赁公司';
                    if (!empty($value['franchisee_id'])) {
                        $db2 = Db::connect('db2');
                        $franchisee_info = $db2->table('franchisee')->field('name')->where('id', $value['franchisee_id'])->find();
                        $list[$key]['referee_info'] = $franchisee_info['name'];
                    }
                } elseif ($value['franchisee_type'] == 5) {
                    $list[$key]['referee_type'] = '城际车队';
                    if (!empty($value['franchisee_id'])) {
                        $db2 = Db::connect('db2');
                        $franchisee_info = $db2->table('fleet')->field('name')->where('id', $value['franchisee_id'])->find();
                        $list[$key]['referee_info'] = $franchisee_info['name'];
                    }
                }
            } else {
                //查询推荐人信息
                $driverInvite = Db::name('driver_invite_record')->where(['invitee_id' => $value['driver_id']])->find();
                if (!empty($driverInvite) && $driverInvite['inviter_type'] == 1) {        //用户
                    $user_phone = Db::name('user')->where(['uid' => $driverInvite['inviter_id'], 'is_del' => 1])->value('user_phone');
                    $list[$key]['referee_info'] = Security::decrypt($user_phone);
                    $list[$key]['referee_type'] = '乘客';
                } elseif (!empty($driverInvite) && $driverInvite['inviter_type'] == 2) {   //司机
                    $driver_phone = Db::name('driver_base')->where(['driver_id' => $driverInvite['inviter_id']])->value('driver_phone');
                    $list[$key]['referee_info'] = Security::decrypt($driver_phone);
                    $list[$key]['referee_type'] = '司机';
                }
            }

            if ($value['taxi_pass'] == 1 && $value['taxi_certificate_pass'] == 1 && $value['comm_pass'] == 1 && $value['sail_pass'] == 1 && $value['carriage_pass'] == 1) {
                $list[$key]['conforName'] = !empty($export) ? '已通过' : '<span style="color: green;">已通过</span>';
            } elseif ($value['taxi_pass'] == 2 && $value['taxi_certificate_pass'] == 2 && $value['comm_pass'] == 2 && $value['sail_pass'] == 2 && $value['carriage_pass'] == 2) {
                $list[$key]['conforName'] = '审核中';
            } elseif ($value['taxi_pass'] == 3 && $value['taxi_certificate_pass'] == 3 && $value['comm_pass'] == 3 && $value['sail_pass'] == 3 && $value['carriage_pass'] == 3) {
                $list[$key]['conforName'] = !empty($export) ? '已拒绝' : '<span style="color: red;">已拒绝</span>';
            } elseif ($value['taxi_pass'] == 4 && $value['taxi_certificate_pass'] == 4 && $value['comm_pass'] == 4 && $value['sail_pass'] == 4 && $value['carriage_pass'] == 4) {
                $list[$key]['conforName'] = !empty($export) ? '待完善' : '<span style="color: blue;">待完善</span>';
            } elseif ($value['taxi_pass'] == 5 && $value['taxi_certificate_pass'] == 5 && $value['comm_pass'] == 5 && $value['sail_pass'] == 5 && $value['carriage_pass'] == 5) {
                $list[$key]['conforName'] = !empty($export) ? '已过期' : '<span style="color: red;">已过期</span>';
            } else {
                $list[$key]['conforName'] = '-';
            }
        }

        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $list
        );
    }


    public function getDriverListD($page, $limit, $data = array(), $export = '')
    {
        $where = [];
        if (!empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['between', [strtotime($data['start']), strtotime($data['end'] . " 23:59:59")]];
        } elseif (!empty($data['start']) && empty($data['end'])) {
            $timeWhere = ['>=', strtotime($data['start'])];
        } elseif (empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['<=', strtotime($data['end'] . " 23:59:59")];
        }
        //注册时间
        if (!empty($data['type']) && $data['type'] == 1 && !empty($timeWhere)) {
            $where['register_time'] = $timeWhere;
        }
        //司机状态搜索
        //查询该司机是否在白名单 - 测试名单内
        $whiteList = Db::name('white_list')->order('id desc')->find();
        if (!empty($data['all_phone'])) {
            if ($data['all_phone'] == 1 && !empty($whiteList['driver_str'])) {        //正式司机
                $where['a.driver_id'] = ['not in', $whiteList['driver_str']];
            } elseif ($data['all_phone'] == 2 && !empty($whiteList['driver_str'])) {   //测试司机
                $where['a.driver_id'] = ['in', $whiteList['driver_str']];
            }
        }
        //登录时间
        if (!empty($data['type']) && $data['type'] == 2 && !empty($timeWhere)) {
            $where['last_login_time'] = $timeWhere;
        }

        //认证状态
        if ($data['auth_status'] != '') {
            $where['a.auth_status'] = $data['auth_status'];
        }
        //标签状态
        if (!empty($data['compliance_type'])) {
            $where['a.compliance_type'] = $data['compliance_type'];
        }
        //手机号码
        if ($data['driver_phone'] != '') {
            $where['a.driver_phone'] = Security::encrypt($data['driver_phone']);
        }
        //合规状态搜索
        if (!empty($data['confor_status'])) {
            $where['c.taxi_pass'] = $data['confor_status'];
            $where['c.taxi_certificate_pass'] = $data['confor_status'];
            $where['c.comm_pass'] = $data['confor_status'];
            $where['c.sail_pass'] = $data['confor_status'];
            $where['c.carriage_pass'] = $data['confor_status'];
        }
        //认证省市
        if (!empty($data['work_city'])) {
            $where['c.work_city'] = $data['work_city'];;
        }
        if ($data['referee_type'] != '') {
            if ($data['referee_type'] == 4) {
                $where['a.franchisee_type'] = 4;
            } elseif ($data['referee_type'] == 5) {
                $where['a.franchisee_type'] = 5;
            } else {
                $where['a.referee_type'] = $data['referee_type'];
            }
        }

        if (session('admin_type') == 5 && session('franchisee_str') != '') {
            $where['a.franchisee_id'] = ['in', session('franchisee_str')];
        } else {
            if ($data['franchisee_info'] != '') {
                $where['a.franchisee_id'] = $data['franchisee_info'];
            }
        }
        //司机类型
        if (!empty($data['driver_type'])) {
            $where['a.driver_type'] = $data['driver_type'];
        }
        //标签信息
        $complianceInfo = config('compliance');
        //分页
        $start = ($page - 1) * $limit;
        $count = Db::name('driver_base a')->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')->
        join('car_info c', 'a.driver_id = c.driver_id', 'left')->where($where)->count();
        $list = Db::name('driver_base a')->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')->
        join('car_info c', 'a.driver_id = c.driver_id', 'left')->limit($start, $limit)->where($where)->field('a.driver_name,a.driver_phone,a.auth_status,a.referee_id,a.referee_type,a.franchisee_type,a.franchisee_id,a.forbid,a.compliance_type,a.is_header,b.auth_type,c.work_province,c.work_city,b.register_time,b.last_login_time,b.join_time,b.logout_time,c.taxi_pass,c.taxi_certificate_pass,c.comm_pass,c.sail_pass,c.carriage_pass,b.id_number,b.license_number,a.driver_sex,b.license_time,b.valid_time')->order('a.driver_id desc')->select();
        foreach ($list as $key => $value) {
            if (!empty($whiteList['driver_str']) && in_array($value['driver_id'], explode(',', $whiteList['driver_str']))) {
                $list[$key]['driver_type_status'] = 1;
            } else {
                $list[$key]['driver_type_status'] = 0;
            }
            $list[$key]['driver_phone'] = Security::decrypt($value['driver_phone']);
            $list[$key]['register_time'] = !empty($value['register_time']) ? date("Y-m-d H:i", $value['register_time']) : '-';
            $list[$key]['last_login_time'] = !empty($value['last_login_time']) ? date("Y-m-d H:i", $value['last_login_time']) : '-';
            //查询省市
            if (!empty($value['work_city'])) {
                $cityName = Db::name('region')->where(['region_id' => $value['work_city']])->value('region_name');
                $list[$key]['city'] = $cityName;
            } else {
                $list[$key]['city'] = '-';
            }
            $list[$key]['serviceLine'] = '300快车';
            $list[$key]['employeeTypeEnum'] = '1自营';
            if ($value['driver_sex'] == 1) {
                $list[$key]['driver_sex'] = "男";
            } else {
                $list[$key]['driver_sex'] = "女";
            }
            $list[$key]['surname'] = mb_substr($value['driver_name'], 0, 1);
            $list[$key]['name'] = mb_substr($value['driver_name'], 1);
            $list[$key]['id_number'] = Security::decrypt($value['id_number'])." ";
            $list[$key]['license_number'] = Security::decrypt($value['license_number'])." ";
            if ($value['valid_time']) {
                $list[$key]['valid_time'] = date('Y-m-d', $value['valid_time']);
            } else {
                $list[$key]['valid_time'] = "";
            }
            if ($value['license_time']) {
                $list[$key]['license_time'] = date('Y-m-d', $value['license_time']);
            } else {
                $list[$key]['license_time'] = "";
            }
            if (!empty($value['franchisee_type'])) {
                if ($value['franchisee_type'] == 4) {
                    $list[$key]['referee_type'] = '快车租赁公司';
                    if (!empty($value['franchisee_id'])) {
                        $db2 = Db::connect('db2');
                        $franchisee_info = $db2->table('franchisee')->field('name')->where('id', $value['franchisee_id'])->find();
                        $list[$key]['referee_info'] = $franchisee_info['name'];
                    }
                } elseif ($value['franchisee_type'] == 5) {
                    $list[$key]['referee_type'] = '城际车队';
                    if (!empty($value['franchisee_id'])) {
                        $db2 = Db::connect('db2');
                        $franchisee_info = $db2->table('fleet')->field('name')->where('id', $value['franchisee_id'])->find();
                        $list[$key]['referee_info'] = $franchisee_info['name'];
                    }
                }
            } else {
                //查询推荐人信息
                $driverInvite = Db::name('driver_invite_record')->where(['invitee_id' => $value['driver_id']])->find();
                if (!empty($driverInvite) && $driverInvite['inviter_type'] == 1) {        //用户
                    $user_phone = Db::name('user')->where(['uid' => $driverInvite['inviter_id'], 'is_del' => 1])->value('user_phone');
                    $list[$key]['referee_info'] = Security::decrypt($user_phone);
                    $list[$key]['referee_type'] = '乘客';
                } elseif (!empty($driverInvite) && $driverInvite['inviter_type'] == 2) {   //司机
                    $driver_phone = Db::name('driver_base')->where(['driver_id' => $driverInvite['inviter_id']])->value('driver_phone');
                    $list[$key]['referee_info'] = Security::decrypt($driver_phone);
                    $list[$key]['referee_type'] = '司机';
                }
            }

            if ($value['taxi_pass'] == 1 && $value['taxi_certificate_pass'] == 1 && $value['comm_pass'] == 1 && $value['sail_pass'] == 1 && $value['carriage_pass'] == 1) {
                $list[$key]['conforName'] = !empty($export) ? '已通过' : '<span style="color: green;">已通过</span>';
            } elseif ($value['taxi_pass'] == 2 && $value['taxi_certificate_pass'] == 2 && $value['comm_pass'] == 2 && $value['sail_pass'] == 2 && $value['carriage_pass'] == 2) {
                $list[$key]['conforName'] = '审核中';
            } elseif ($value['taxi_pass'] == 3 && $value['taxi_certificate_pass'] == 3 && $value['comm_pass'] == 3 && $value['sail_pass'] == 3 && $value['carriage_pass'] == 3) {
                $list[$key]['conforName'] = !empty($export) ? '已拒绝' : '<span style="color: red;">已拒绝</span>';
            } elseif ($value['taxi_pass'] == 4 && $value['taxi_certificate_pass'] == 4 && $value['comm_pass'] == 4 && $value['sail_pass'] == 4 && $value['carriage_pass'] == 4) {
                $list[$key]['conforName'] = !empty($export) ? '待完善' : '<span style="color: blue;">待完善</span>';
            } elseif ($value['taxi_pass'] == 5 && $value['taxi_certificate_pass'] == 5 && $value['comm_pass'] == 5 && $value['sail_pass'] == 5 && $value['carriage_pass'] == 5) {
                $list[$key]['conforName'] = !empty($export) ? '已过期' : '<span style="color: red;">已过期</span>';
            } else {
                $list[$key]['conforName'] = '-';
            }
        }

        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $list
        );
    }


    public function getCarList($page, $limit, $data = array(), $export = '')
    {
        $where = [];
        if (!empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['between', [strtotime($data['start']), strtotime($data['end'] . " 23:59:59")]];
        } elseif (!empty($data['start']) && empty($data['end'])) {
            $timeWhere = ['>=', strtotime($data['start'])];
        } elseif (empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['<=', strtotime($data['end'] . " 23:59:59")];
        }
        //注册时间
        if (!empty($data['type']) && $data['type'] == 1 && !empty($timeWhere)) {
            $where['register_time'] = $timeWhere;
        }
        //司机状态搜索
        //查询该司机是否在白名单 - 测试名单内
        $whiteList = Db::name('white_list')->order('id desc')->find();
        if (!empty($data['all_phone'])) {
            if ($data['all_phone'] == 1 && !empty($whiteList['driver_str'])) {        //正式司机
                $where['a.driver_id'] = ['not in', $whiteList['driver_str']];
            } elseif ($data['all_phone'] == 2 && !empty($whiteList['driver_str'])) {   //测试司机
                $where['a.driver_id'] = ['in', $whiteList['driver_str']];
            }
        }
        //登录时间
        if (!empty($data['type']) && $data['type'] == 2 && !empty($timeWhere)) {
            $where['last_login_time'] = $timeWhere;
        }

        //认证状态
        if ($data['auth_status'] != '') {
            $where['a.auth_status'] = $data['auth_status'];
        }
        //标签状态
        if (!empty($data['compliance_type'])) {
            $where['a.compliance_type'] = $data['compliance_type'];
        }
        //手机号码
        if ($data['driver_phone'] != '') {
            $where['a.driver_phone'] = Security::encrypt($data['driver_phone']);
        }
        //合规状态搜索
        if (!empty($data['confor_status'])) {
            $where['c.taxi_pass'] = $data['confor_status'];
            $where['c.taxi_certificate_pass'] = $data['confor_status'];
            $where['c.comm_pass'] = $data['confor_status'];
            $where['c.sail_pass'] = $data['confor_status'];
            $where['c.carriage_pass'] = $data['confor_status'];
        }
        //认证省市
        if (!empty($data['work_city'])) {
            $where['c.work_city'] = $data['work_city'];;
        }
        if ($data['referee_type'] != '') {
            if ($data['referee_type'] == 4) {
                $where['a.franchisee_type'] = 4;
            } elseif ($data['referee_type'] == 5) {
                $where['a.franchisee_type'] = 5;
            } else {
                $where['a.referee_type'] = $data['referee_type'];
            }
        }

        if (session('admin_type') == 5 && session('franchisee_str') != '') {
            $where['a.franchisee_id'] = ['in', session('franchisee_str')];
        } else {
            if ($data['franchisee_info'] != '') {
                $where['a.franchisee_id'] = $data['franchisee_info'];
            }
        }
        //司机类型
        if (!empty($data['driver_type'])) {
            $where['a.driver_type'] = $data['driver_type'];
        }
        //标签信息
        $complianceInfo = config('compliance');
        //分页
        $start = ($page - 1) * $limit;
        $count = Db::name('driver_base a')->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')->
        join('car_info c', 'a.driver_id = c.driver_id', 'left')->where($where)->count();
        $list = Db::name('driver_base a')->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')->
        join('car_info c', 'a.driver_id = c.driver_id', 'left')->limit($start, $limit)->where($where)->field('c.*')->order('a.driver_id desc')->select();
        foreach ($list as $key => $value) {
            $list[$key]['city'] = Db::name('region')->where('region_id', $value['work_city'])->value('region_name');
            $list[$key]['plateNoFirst'] = mb_substr(Security::decrypt($value['car_plate']), 0, 1);
            $list[$key]['car_plate'] = mb_substr(Security::decrypt($value['car_plate']),1);
            $list[$key]['brand'] = Security::decrypt($value['car_brand']);
            $list[$key]['color'] = Security::decrypt($value['color']);
            $list[$key]['vin'] = Security::decrypt($value['vin']);
            $list[$key]['car_vin'] = Security::decrypt($value['car_vin']);
            switch ($list[$key]['color']) {
                case "黑色":
                    $list[$key]['color'] = "1" . $list[$key]['color'];
                    break;
                case "白色":
                    $list[$key]['color'] = "2" . $list[$key]['color'];
                    break;
                case "红色":
                    $list[$key]['color'] = "3" . $list[$key]['color'];
                    break;
                case "银色":
                    $list[$key]['color'] = "4" . $list[$key]['color'];
                    break;
                case "蓝色":
                    $list[$key]['color'] = "5" . $list[$key]['color'];
                    break;
                case "棕色":
                    $list[$key]['color'] = "6" . $list[$key]['color'];
                    break;
                case "绿色":
                    $list[$key]['color'] = "7" . $list[$key]['color'];
                    break;
                case "灰色":
                    $list[$key]['color'] = "8" . $list[$key]['color'];
                    break;
                case "黄色":
                    $list[$key]['color'] = "9" . $list[$key]['color'];
                    break;
                case "橙色":
                    $list[$key]['color'] = "10" . $list[$key]['color'];
                    break;
                case "粉色":
                    $list[$key]['color'] = "11" . $list[$key]['color'];
                    break;
                default:
                    $list[$key]['color'] = "100其它";
                    break;
            }
            $list[$key]['owner'] = Security::decrypt($value['owner']);
            if (strstr($list[$key]['brand'], '-')) {
                $list[$key]['brand'] = strstr($list[$key]['brand'], '-', true);
                $list[$key]['model'] = strstr(Security::decrypt($value['car_brand']), '-');
                $list[$key]['model'] = mb_substr($list[$key]['model'], 1);
            }
            $list[$key]['levelIdEnum'] = '1A级车';

            if ($value['register_at']) {
                $list[$key]['register_at'] = date('Y-m-d', $value['register_at']);
            } else {
                $list[$key]['register_at'] = "";
            }
        }
        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $list
        );
    }


    public function getBannedList($page, $limit, $data = array(), $field = '*', $export = '')
    {
        $where = [];
        if (!empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['between', [strtotime($data['start']), strtotime($data['end'] . " 23:59:59")]];
        } elseif (!empty($data['start']) && empty($data['end'])) {
            $timeWhere = ['>=', strtotime($data['start'])];
        } elseif (empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['<=', strtotime($data['end'] . " 23:59:59")];
        }

        //司机状态搜索
        //查询该司机是否在白名单 - 测试名单内
        $whiteList = Db::name('white_list')->order('id desc')->find();
        if (!empty($data['all_phone'])) {
            if ($data['all_phone'] == 1 && !empty($whiteList['driver_str'])) {        //正式司机
                $where['a.driver_id'] = ['not in', $whiteList['driver_str']];
            } elseif ($data['all_phone'] == 2 && !empty($whiteList['driver_str'])) {   //测试司机
                $where['a.driver_id'] = ['in', $whiteList['driver_str']];
            }
        }
        //封禁时间
        if (!empty($timeWhere)) {
            $where['forbid_time_start'] = $timeWhere;
        }
        //手机号码
        if ($data['driver_phone'] != '') {
            $where['a.driver_phone'] = Security::encrypt($data['driver_phone']);
        }

        //认证省市
        if (!empty($data['work_city'])) {
            $where['c.work_city'] = $data['work_city'];;
        }
        if ($data['referee_type'] != '') {
            if ($data['referee_type'] == 4) {
                $where['a.franchisee_type'] = 4;
            } elseif ($data['referee_type'] == 5) {
                $where['a.franchisee_type'] = 5;
            } else {
                $where['a.referee_type'] = $data['referee_type'];
            }
        }

        if (session('admin_type') == 5 && session('franchisee_str') != '') {
            $where['a.franchisee_id'] = ['in', session('franchisee_str')];
        } else {
            if ($data['franchisee_info'] != '') {
                $where['a.franchisee_id'] = $data['franchisee_info'];
            }
        }


        //司机类型
        if (!empty($data['driver_type_info']) && $data['driver_type_info'] == 2) {
            $where['a.driver_type'] = 2;
            $where['a.auth_status'] = 1;
        }

        //标签信息
        $complianceInfo = config('compliance');
        //分页
        $start = ($page - 1) * $limit;
        $count = Db::name('driver_base a')->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')->
        join('car_info c', 'a.driver_id = c.driver_id', 'left')->where($where)->where('a.forbid', 'in', "1,3")->count();
        $list = Db::name('driver_base a')->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')->
        join('car_info c', 'a.driver_id = c.driver_id', 'left')->limit($start, $limit)->where($where)->where('a.forbid', 'in', "1,3")->field($field)->order('a.driver_id desc')->select();
        foreach ($list as $key => $value) {
            if (!empty($whiteList['driver_str']) && in_array($value['driver_id'], explode(',', $whiteList['driver_str']))) {
                $list[$key]['driver_type_status'] = 1;
            } else {
                $list[$key]['driver_type_status'] = 0;
            }
            $list[$key]['forbid'] = forbidStatus($value['forbid']);
            $list[$key]['forbid_content'] = $value['forbid_content'];
            if ($value['forbid_time_start']) {
                $list[$key]['forbid_time_start'] = date('Y/m/d H:i:s', $value['forbid_time_start']);
            }
//            if (!$value['forbid_time_end']||$value['forbid_time_end']>time()) {
//                $list[$key]['forbid_time_end']="-";
//            }else {
//                $list[$key]['forbid_time_end'] = date('Y/m/d H:i:s', $value['forbid_time_end']);
//            }

            $list[$key]['driver_phone'] = Security::decrypt($value['driver_phone']);
            $list[$key]['register_time'] = !empty($value['register_time']) ? date("Y-m-d H:i", $value['register_time']) : '-';
            $list[$key]['last_login_time'] = !empty($value['last_login_time']) ? date("Y-m-d H:i", $value['last_login_time']) : '-';

            //$list[$key]['join_time']        = !empty($value['join_time'])?date("Y-m-d H:i",$value['join_time']):'-';
            //$list[$key]['logout_time']      = !empty($value['logout_time'])?date("Y-m-d H:i",$value['logout_time']):'-';
            //查询省市
            if (!empty($value['work_province']) && !empty($value['work_city'])) {
                $provinceName = Db::name('region')->where(['region_id' => $value['work_province']])->value('region_name');
                $cityName = Db::name('region')->where(['region_id' => $value['work_city']])->value('region_name');
                $list[$key]['provinceCity'] = $provinceName . ' / ' . $cityName;
            } else {
                $list[$key]['provinceCity'] = '-';
            }

            //投诉次数
            if (!empty($data['type']) && $data['type'] == 3 && !empty($timeWhere)) {
                $list[$key]['complaintNum'] = Db::name('complaint')->where('appeal_time', $timeWhere)->where(['driver_id' => $value['driver_id']])->count();
            } else {
                $list[$key]['complaintNum'] = Db::name('complaint')->where(['driver_id' => $value['driver_id']])->count();
            }
            //资料
            $is_supply = Db::name('driver_info_supplement')->where('driver_id', $value['driver_id'])->find();
            if ($is_supply) {
                $list[$key]['is_supplement'] = 1; //已补录
            } else {
                $list[$key]['is_supplement'] = 2; //未补录
            }


            if (!empty($value['franchisee_type'])) {
                if ($value['franchisee_type'] == 4) {
                    $list[$key]['referee_type'] = '快车租赁公司';
                    if (!empty($value['franchisee_id'])) {
                        $db2 = Db::connect('db2');
                        $franchisee_info = $db2->table('franchisee')->field('name')->where('id', $value['franchisee_id'])->find();
                        $list[$key]['referee_info'] = $franchisee_info['name'];
                    }
                } elseif ($value['franchisee_type'] == 5) {
                    $list[$key]['referee_type'] = '城际车队';
                    if (!empty($value['franchisee_id'])) {
                        $db2 = Db::connect('db2');
                        $franchisee_info = $db2->table('fleet')->field('name')->where('id', $value['franchisee_id'])->find();
                        $list[$key]['referee_info'] = $franchisee_info['name'];
                    }
                }
            } else {
                //查询推荐人信息
                $driverInvite = Db::name('driver_invite_record')->where(['invitee_id' => $value['driver_id']])->find();
                if (!empty($driverInvite) && $driverInvite['inviter_type'] == 1) {        //用户
                    $user_phone = Db::name('user')->where(['uid' => $driverInvite['inviter_id'], 'is_del' => 1])->value('user_phone');
                    $list[$key]['referee_info'] = Security::decrypt($user_phone);
                    $list[$key]['referee_type'] = '乘客';
                } elseif (!empty($driverInvite) && $driverInvite['inviter_type'] == 2) {   //司机
                    $driver_phone = Db::name('driver_base')->where(['driver_id' => $driverInvite['inviter_id']])->value('driver_phone');
                    $list[$key]['referee_info'] = Security::decrypt($driver_phone);
                    $list[$key]['referee_type'] = '司机';
                }
                /*if($value['referee_type'] == 1) { //司机
                    $list[$key]['referee_type'] = '司机';
                    $list[$key]['referee_info'] = Security::decrypt($value['driver_phone']);
                } elseif($value['referee_type'] == 2) { //乘客
                    $list[$key]['referee_type'] = '乘客';
                    if(!empty($value['referee_id'])) {
                        $user_res = Db::table('xm_user')->field('user_phone')->where('uid',$value['referee_id'])->find();
                        $list[$key]['referee_info'] = Security::decrypt($user_res['user_phone']);
                    }
                }*/
            }

        }
        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $list
        );
    }

    //司机在线记录列表
    public function onlineList($page, $limit, $data = array())
    {
        if (!empty($data['online_start']) && !empty($data['online_end'])) {
            $where['a.start_time'] = ['between', [strtotime($data['online_start']), strtotime($data['online_end'])]];
        } elseif (!empty($data['online_start']) && empty($data['online_end'])) {
            $where['a.start_time'] = ['>=', strtotime($data['online_start'])];
        } elseif (empty($data['online_start']) && !empty($data['online_end'])) {
            $where['a.start_time'] = ['<=', strtotime($data['online_end'])];
        }
        if (!empty($data['offline_start']) && !empty($data['offline_end'])) {
            $where['a.end_time'] = ['between', [strtotime($data['offline_start']), strtotime($data['offline_start'])]];
        } elseif (!empty($data['offline_start']) && empty($data['offline_end'])) {
            $where['a.end_time'] = ['>=', strtotime($data['offline_start'])];
        } elseif (empty($data['offline_start']) && !empty($data['offline_end'])) {
            $where['a.end_time'] = ['<=', strtotime($data['offline_end'])];
        }
        //手机号码
        if (!empty($data['driver_phone'])) {
            $where['b.driver_phone'] = Security::encrypt($data['driver_phone']);
        }
        //分页
        $field = 'a.*,b.driver_phone,b.driver_name';
        $start = ($page - 1) * $limit;
        $count = Db::name('driver_online_time a')->join('driver_base b', 'a.driver_id = b.driver_id', 'LEFT')->where($where)->count();
        $list = Db::name('driver_online_time a')->join('driver_base b', 'a.driver_id = b.driver_id', 'LEFT')->limit($start, $limit)->where($where)->field($field)->order('a.id desc')->select();


        foreach ($list as $key => $value) {
            $list[$key]['driver_phone'] = Security::decrypt($value['driver_phone']);
            $list[$key]['start_time'] = !empty($value['start_time']) ? date("Y-m-d H:i:s", $value['start_time']) : '-';
            $list[$key]['end_time'] = !empty($value['end_time']) ? date("Y-m-d H:i:s", $value['end_time']) : '-';
            if (!empty($value['city_id'])) {
                $list[$key]['city'] = Db::name('region')->where(['region_id' => $value['city_id']])->value('region_name');
            } else {
                $list[$key]['city'] = '-';
            }
            if (empty($value['end_time'])) {
                $list[$key]['sum_time'] = get_second_h_m(time() - $value['start_time']);
            } else {
                $list[$key]['sum_time'] = get_second_h_m($value['end_time'] - $value['start_time']);
            }
        }
        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $list
        );
    }

    public function getDriverByDid($did, $string = 'a.*')
    {
        return Db::table("xm_driver_base a")->join('xm_driver_info e', 'e.driver_id = a.driver_id', 'LEFT')
            ->join('__REGION__ b', 'b.region_id=e.work_province', 'LEFT')
            ->join('__REGION__ c', 'c.region_id=e.work_city', 'LEFT')
            ->join('__REGION__ d', 'd.region_id=e.work_county', 'LEFT')
            ->field($string . ",b.region_name as province,c.region_name as city,d.region_name as county")
            ->where(array('a.driver_id' => $did))->find();

    }

    public function getDriverMoneyList($page, $limit, $map = array(), $field = 'a.*')
    {
        return Db::table('xm_driver_money a')->join(['xm_driver' => 'b'], 'a.driver_id = b.driver_id', 'LEFT')
            ->page($page, $limit)->where($map)->field($field)->order('id desc')->select();
    }

    public function searchDriver($map, $field = '*', $flag = true)
    {
        return $flag ? Db::name('driver_base')->where($map)->field($field)->select()
            : Db::name('driver_base')->where($map)->column($field);
    }
    //司机车辆绑定
    public function getDriverListDC($page, $limit, $data = array(), $export = '')
    {
        $where = [];
        if (!empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['between', [strtotime($data['start']), strtotime($data['end'] . " 23:59:59")]];
        } elseif (!empty($data['start']) && empty($data['end'])) {
            $timeWhere = ['>=', strtotime($data['start'])];
        } elseif (empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['<=', strtotime($data['end'] . " 23:59:59")];
        }
        //注册时间
        if (!empty($data['type']) && $data['type'] == 1 && !empty($timeWhere)) {
            $where['register_time'] = $timeWhere;
        }
        //司机状态搜索
        //查询该司机是否在白名单 - 测试名单内
        $whiteList = Db::name('white_list')->order('id desc')->find();
        if (!empty($data['all_phone'])) {
            if ($data['all_phone'] == 1 && !empty($whiteList['driver_str'])) {        //正式司机
                $where['a.driver_id'] = ['not in', $whiteList['driver_str']];
            } elseif ($data['all_phone'] == 2 && !empty($whiteList['driver_str'])) {   //测试司机
                $where['a.driver_id'] = ['in', $whiteList['driver_str']];
            }
        }
        //登录时间
        if (!empty($data['type']) && $data['type'] == 2 && !empty($timeWhere)) {
            $where['last_login_time'] = $timeWhere;
        }

        //认证状态
        if ($data['auth_status'] != '') {
            $where['a.auth_status'] = $data['auth_status'];
        }
        //标签状态
        if (!empty($data['compliance_type'])) {
            $where['a.compliance_type'] = $data['compliance_type'];
        }
        //手机号码
        if ($data['driver_phone'] != '') {
            $where['a.driver_phone'] = Security::encrypt($data['driver_phone']);
        }
        //合规状态搜索
        if (!empty($data['confor_status'])) {
            $where['c.taxi_pass'] = $data['confor_status'];
            $where['c.taxi_certificate_pass'] = $data['confor_status'];
            $where['c.comm_pass'] = $data['confor_status'];
            $where['c.sail_pass'] = $data['confor_status'];
            $where['c.carriage_pass'] = $data['confor_status'];
        }
        //认证省市
        if (!empty($data['work_city'])) {
            $where['c.work_city'] = $data['work_city'];;
        }
        if ($data['referee_type'] != '') {
            if ($data['referee_type'] == 4) {
                $where['a.franchisee_type'] = 4;
            } elseif ($data['referee_type'] == 5) {
                $where['a.franchisee_type'] = 5;
            } else {
                $where['a.referee_type'] = $data['referee_type'];
            }
        }

        if (session('admin_type') == 5 && session('franchisee_str') != '') {
            $where['a.franchisee_id'] = ['in', session('franchisee_str')];
        } else {
            if ($data['franchisee_info'] != '') {
                $where['a.franchisee_id'] = $data['franchisee_info'];
            }
        }
        //司机类型
        if (!empty($data['driver_type'])) {
            $where['a.driver_type'] = $data['driver_type'];
        }
        //标签信息
        $complianceInfo = config('compliance');
        //分页
        $start = ($page - 1) * $limit;
        $count = Db::name('driver_base a')->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')->
        join('car_info c', 'a.driver_id = c.driver_id', 'left')->where($where)->count();
        $list = Db::name('driver_base a')->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')->
        join('car_info c', 'a.driver_id = c.driver_id', 'left')->limit($start, $limit)->where($where)->field('a.driver_name,a.driver_phone,a.auth_status,a.referee_id,a.referee_type,a.franchisee_type,a.franchisee_id,a.forbid,a.compliance_type,a.is_header,b.auth_type,c.work_province,c.work_city,b.register_time,b.last_login_time,b.join_time,b.logout_time,c.taxi_pass,c.taxi_certificate_pass,c.comm_pass,c.sail_pass,c.carriage_pass,b.id_number,b.license_number,a.driver_sex,b.license_time,b.valid_time,c.car_plate')->order('a.driver_id desc')->select();
        foreach ($list as $key => $value) {
            if (!empty($whiteList['driver_str']) && in_array($value['driver_id'], explode(',', $whiteList['driver_str']))) {
                $list[$key]['driver_type_status'] = 1;
            } else {
                $list[$key]['driver_type_status'] = 0;
            }
            $list[$key]['driver_phone'] = Security::decrypt($value['driver_phone']);
            $list[$key]['car_plate'] = Security::decrypt($value['car_plate']);
            $list[$key]['register_time'] = !empty($value['register_time']) ? date("Y-m-d H:i", $value['register_time']) : '-';
            $list[$key]['last_login_time'] = !empty($value['last_login_time']) ? date("Y-m-d H:i", $value['last_login_time']) : '-';
            //查询省市
            if (!empty($value['work_city'])) {
                $cityName = Db::name('region')->where(['region_id' => $value['work_city']])->value('region_name');
                $list[$key]['city'] = $cityName;
            } else {
                $list[$key]['city'] = '-';
            }
            $list[$key]['serviceLine'] = '300快车';
            $list[$key]['employeeTypeEnum'] = '1自营';
            if ($value['driver_sex'] == 1) {
                $list[$key]['driver_sex'] = "男";
            } else {
                $list[$key]['driver_sex'] = "女";
            }
            $list[$key]['surname'] = mb_substr($value['driver_name'], 0, 1);
            $list[$key]['name'] = mb_substr($value['driver_name'], 1);
            $list[$key]['id_number'] = Security::decrypt($value['id_number'])." ";
            $list[$key]['license_number'] = Security::decrypt($value['license_number'])." ";
            if ($value['valid_time']) {
                $list[$key]['valid_time'] = date('Y-m-d', $value['valid_time']);
            } else {
                $list[$key]['valid_time'] = "";
            }
            if ($value['license_time']) {
                $list[$key]['license_time'] = date('Y-m-d', $value['license_time']);
            } else {
                $list[$key]['license_time'] = "";
            }
            if (!empty($value['franchisee_type'])) {
                if ($value['franchisee_type'] == 4) {
                    $list[$key]['referee_type'] = '快车租赁公司';
                    if (!empty($value['franchisee_id'])) {
                        $db2 = Db::connect('db2');
                        $franchisee_info = $db2->table('franchisee')->field('name')->where('id', $value['franchisee_id'])->find();
                        $list[$key]['referee_info'] = $franchisee_info['name'];
                    }
                } elseif ($value['franchisee_type'] == 5) {
                    $list[$key]['referee_type'] = '城际车队';
                    if (!empty($value['franchisee_id'])) {
                        $db2 = Db::connect('db2');
                        $franchisee_info = $db2->table('fleet')->field('name')->where('id', $value['franchisee_id'])->find();
                        $list[$key]['referee_info'] = $franchisee_info['name'];
                    }
                }
            } else {
                //查询推荐人信息
                $driverInvite = Db::name('driver_invite_record')->where(['invitee_id' => $value['driver_id']])->find();
                if (!empty($driverInvite) && $driverInvite['inviter_type'] == 1) {        //用户
                    $user_phone = Db::name('user')->where(['uid' => $driverInvite['inviter_id'], 'is_del' => 1])->value('user_phone');
                    $list[$key]['referee_info'] = Security::decrypt($user_phone);
                    $list[$key]['referee_type'] = '乘客';
                } elseif (!empty($driverInvite) && $driverInvite['inviter_type'] == 2) {   //司机
                    $driver_phone = Db::name('driver_base')->where(['driver_id' => $driverInvite['inviter_id']])->value('driver_phone');
                    $list[$key]['referee_info'] = Security::decrypt($driver_phone);
                    $list[$key]['referee_type'] = '司机';
                }
            }

            if ($value['taxi_pass'] == 1 && $value['taxi_certificate_pass'] == 1 && $value['comm_pass'] == 1 && $value['sail_pass'] == 1 && $value['carriage_pass'] == 1) {
                $list[$key]['conforName'] = !empty($export) ? '已通过' : '<span style="color: green;">已通过</span>';
            } elseif ($value['taxi_pass'] == 2 && $value['taxi_certificate_pass'] == 2 && $value['comm_pass'] == 2 && $value['sail_pass'] == 2 && $value['carriage_pass'] == 2) {
                $list[$key]['conforName'] = '审核中';
            } elseif ($value['taxi_pass'] == 3 && $value['taxi_certificate_pass'] == 3 && $value['comm_pass'] == 3 && $value['sail_pass'] == 3 && $value['carriage_pass'] == 3) {
                $list[$key]['conforName'] = !empty($export) ? '已拒绝' : '<span style="color: red;">已拒绝</span>';
            } elseif ($value['taxi_pass'] == 4 && $value['taxi_certificate_pass'] == 4 && $value['comm_pass'] == 4 && $value['sail_pass'] == 4 && $value['carriage_pass'] == 4) {
                $list[$key]['conforName'] = !empty($export) ? '待完善' : '<span style="color: blue;">待完善</span>';
            } elseif ($value['taxi_pass'] == 5 && $value['taxi_certificate_pass'] == 5 && $value['comm_pass'] == 5 && $value['sail_pass'] == 5 && $value['carriage_pass'] == 5) {
                $list[$key]['conforName'] = !empty($export) ? '已过期' : '<span style="color: red;">已过期</span>';
            } else {
                $list[$key]['conforName'] = '-';
            }
        }
        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $list
        );
    }

    //约约司机导出信息
    public function getDriverListyyD($page, $limit, $data = array(), $export = '')
    {
        $where = [];
        if (!empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['between', [strtotime($data['start']), strtotime($data['end'] . " 23:59:59")]];
        } elseif (!empty($data['start']) && empty($data['end'])) {
            $timeWhere = ['>=', strtotime($data['start'])];
        } elseif (empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['<=', strtotime($data['end'] . " 23:59:59")];
        }
        //注册时间
        if (!empty($data['type']) && $data['type'] == 1 && !empty($timeWhere)) {
            $where['register_time'] = $timeWhere;
        }
        //司机状态搜索
        //查询该司机是否在白名单 - 测试名单内
        $whiteList = Db::name('white_list')->order('id desc')->find();
        if (!empty($data['all_phone'])) {
            if ($data['all_phone'] == 1 && !empty($whiteList['driver_str'])) {        //正式司机
                $where['a.driver_id'] = ['not in', $whiteList['driver_str']];
            } elseif ($data['all_phone'] == 2 && !empty($whiteList['driver_str'])) {   //测试司机
                $where['a.driver_id'] = ['in', $whiteList['driver_str']];
            }
        }
        //登录时间
        if (!empty($data['type']) && $data['type'] == 2 && !empty($timeWhere)) {
            $where['last_login_time'] = $timeWhere;
        }

        //认证状态
        if ($data['auth_status'] != '') {
            $where['a.auth_status'] = $data['auth_status'];
        }
        //标签状态
        if (!empty($data['compliance_type'])) {
            $where['a.compliance_type'] = $data['compliance_type'];
        }
        //手机号码
        if ($data['driver_phone'] != '') {
            $where['a.driver_phone'] = Security::encrypt($data['driver_phone']);
        }
        //合规状态搜索
        if (!empty($data['confor_status'])) {
            $where['c.taxi_pass'] = $data['confor_status'];
            $where['c.taxi_certificate_pass'] = $data['confor_status'];
            $where['c.comm_pass'] = $data['confor_status'];
            $where['c.sail_pass'] = $data['confor_status'];
            $where['c.carriage_pass'] = $data['confor_status'];
        }
        //认证省市
        if (!empty($data['work_city'])) {
            $where['c.work_city'] = $data['work_city'];;
        }
        if ($data['referee_type'] != '') {
            if ($data['referee_type'] == 4) {
                $where['a.franchisee_type'] = 4;
            } elseif ($data['referee_type'] == 5) {
                $where['a.franchisee_type'] = 5;
            } else {
                $where['a.referee_type'] = $data['referee_type'];
            }
        }

        if (session('admin_type') == 5 && session('franchisee_str') != '') {
            $where['a.franchisee_id'] = ['in', session('franchisee_str')];
        } else {
            if ($data['franchisee_info'] != '') {
                $where['a.franchisee_id'] = $data['franchisee_info'];
            }
        }
        //司机类型
        if (!empty($data['driver_type'])) {
            $where['a.driver_type'] = $data['driver_type'];
        }
//        //标签信息
//        $complianceInfo = config('compliance');
//        //分页
//        $start = ($page - 1) * $limit;

        $list = Db::name('driver_base a')
            ->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')
            ->join('car_info c', 'a.driver_id = c.driver_id', 'left')
            ->join('driver_info_supplement s','a.driver_id = s.driver_id','left')
            ->join('moreq_sjpx px', 'a.driver_id = px.driver_id', 'left')
            ->field('a.driver_name,a.driver_phone,a.auth_status,a.referee_id,a.referee_type,a.franchisee_type,a.franchisee_id,a.forbid,a.compliance_type,a.is_header,b.license_time,a.check_pass_time,b.valid_time,b.auth_type,c.work_province,c.work_city,b.register_time,b.last_login_time,b.join_time,b.logout_time,c.taxi_pass,c.taxi_certificate_pass,c.comm_pass,c.sail_pass,c.carriage_pass,b.id_number,b.license_number,b.license_time,b.valid_time,px.courseName,px.courseStartDate,px.courseEndDate,px.courseDays,s.*')
            ->where($where)
            ->page($page, $limit)
            ->order('a.driver_id desc')
            ->select();

        $count = Db::name('driver_base a')
            ->join('driver_info b', 'a.driver_id = b.driver_id', 'left')
            ->join('car_info c', 'a.driver_id = c.driver_id', 'left')
            ->join('driver_info_supplement s','a.driver_id = s.driver_id','left')
            ->join('moreq_sjpx px', 'a.driver_id = px.driver_id', 'left')
            ->where($where)
            ->count();

        foreach ($list as $key => $value) {
            if (!empty($whiteList['driver_str']) && in_array($value['driver_id'], explode(',', $whiteList['driver_str']))) {
                $list[$key]['driver_type_status'] = 1;
            } else {
                $list[$key]['driver_type_status'] = 0;
            }
            $list[$key]['driver_phone'] = Security::decrypt($value['driver_phone']);
            $list[$key]['register_time'] = !empty($value['register_time']) ? date("Y-m-d H:i", $value['register_time']) : '-';
            $list[$key]['last_login_time'] = !empty($value['last_login_time']) ? date("Y-m-d H:i", $value['last_login_time']) : '-';
            //查询省市
            $cityName = '';
            if (!empty($value['work_city'])) {
                $cityName = Db::name('region')->where(['region_id' => $value['work_city']])->value('region_name');
                $list[$key]['city'] = $cityName;
            } else {
                $list[$key]['city'] = '';
            }
            $list[$key]['serviceLine'] = '300快车';
            $list[$key]['employeeTypeEnum'] = '3带车加盟';

            switch($value['service_type']) { //服务类型
                case 1 :
                    $list[$key]['serviceType1Enum'] = "3私人小客车合乘"; //对应 约约 私人小客车合乘
                    break;
                case 2 :
                    $list[$key]['serviceType1Enum'] = "2巡游出租汽车";
                    break;
                case 3 :
                    $list[$key]['serviceType1Enum'] = "1网约预约出租车";
                    break;
                default:
                    $list[$key]['serviceType1Enum'] = '1网约预约出租车'; //默认
            }

            if ($value['sex'] == 1) {
                $list[$key]['driver_sex'] = "1男";
            } elseif($value['sex'] == 2) {
                $list[$key]['driver_sex'] = "2女";
            } else {
                if(empty($value['id_number'])) { //处理未存 身份证号
                    $rand_res = rand(0,9);
                    if($rand_res < 5) {
                        $list[$key]['driver_sex'] = "1男";
                    } else {
                        $list[$key]['driver_sex'] = "2女";
                    }
                } else { //利用身份证判断 性别
                    $sexint = (int) substr(Security::decrypt($value['id_number']), 16, 1);
                    $sex_res = $sexint % 2 === 0 ? '2' : '1';
                    if($sex_res == 1) { // 1男 2女
                        $list[$key]['driver_sex'] = "1男";
                    } else {
                        $list[$key]['driver_sex'] = "2女";
                    }
                }
            }

            switch($value['is_merry']) { //婚姻状况
                case 10 :
                    $list[$key]['maritalStatusEnum'] = "10未婚";
                    break;
                case 20 :
                    $list[$key]['maritalStatusEnum'] = "20已婚";
                    break;
                case 30 :
                    $list[$key]['maritalStatusEnum'] = "40离婚";
                    break;
                default:
                    $rand_num = mt_rand(0,9);
                    if($rand_num == 0) {
                        $list[$key]['maritalStatusEnum'] = '10未婚';
                    } else {
                        $list[$key]['maritalStatusEnum'] = '20已婚';
                    }
            }

            switch($value['language_level_enum']) { //外语能力
                case 1 :
                    $list[$key]['languageLevelEnum'] = "1精通";
                    break;
                case 2 :
                    $list[$key]['languageLevelEnum'] = "2熟练";
                    break;
                case 3 :
                    $list[$key]['languageLevelEnum'] = "3良好";
                    break;
                case 4 :
                    $list[$key]['languageLevelEnum'] = "4一般";
                    break;
                default:
                    $arr_info = ['1精通','2熟练','3良好','4一般'];
                    $arr_info_key = array_rand($arr_info,1);
                    $list[$key]['languageLevelEnum'] = $arr_info[$arr_info_key];
            }

            switch($value['education_enum']) { //学历
                case 17 :
                    $list[$key]['educationEnum'] = "17研究生";
                    break;
                case 21 :
                    $list[$key]['educationEnum'] = "21大学本科";
                    break;
                case 31 :
                    $list[$key]['educationEnum'] = "31大学专科";
                    break;
                case 41 :
                    $list[$key]['educationEnum'] = "41中等专科毕业";
                    break;
                case 61 :
                    $list[$key]['educationEnum'] = "61普通高中毕业";
                    break;
                case 71 :
                    $list[$key]['educationEnum'] = "71初中毕业";
                    break;
                case 81 :
                    $list[$key]['educationEnum'] = "81小学毕业";
                    break;
                default:
                    $arr = ['17研究生','21大学本科','31大学专科','41中等专科毕业','61普通高中毕业','71初中毕业','81小学毕业'];
                    $arr_key = array_rand($arr,1);
                    $list[$key]['educationEnum'] = $arr[$arr_key];
            }

            //补录信息
//            $list[$key]['licenseClass'] = 'C1';  //准驾车型
            $list[$key]['licenseClass'] = empty($value['allow_model'])?'C1':Security::decrypt($value['allow_model']);  //准驾车型
            $list[$key]['firstIssueDate'] = empty($value['first_receive_license_date'])?date('Y-m-d', $value['license_time']):Security::decrypt($value['first_receive_license_date']);  //初次领证日期
            $list[$key]['effectiveDate'] = empty($value['license_time'])?'无数据':date('Y-m-d', $value['license_time']);  //有效起始日期
            $list[$key]['expiryDate'] = empty($value['valid_time'])?'无数据':date('Y-m-d', $value['valid_time']);  //有效截止日期

            $list[$key]['trafficViolationTimes'] = empty($value['traffic_violation_times'])?0:$value['traffic_violation_times'];  //交通违章次数
            switch ($value['nationality']) {
                case 1 :
                    $nationality = '1汉族';
                    break;
                case 2 :
                    $nationality = '2蒙古族';
                    break;
                case 3 :
                    $nationality = '3回族';
                    break;
                case 4 :
                    $nationality = '4藏族';
                    break;
                case 5 :
                    $nationality = '5维吾尔族';
                    break;
                case 6 :
                    $nationality = '6苗族';
                    break;
                case 7 :
                    $nationality = '7彝族';
                    break;
                case 8 :
                    $nationality = '8壮族';
                    break;
                case 9 :
                    $nationality = '9布依族';
                    break;
                case 10 :
                    $nationality = '10朝鲜族';
                    break;
                case 57 :
                    $nationality = '57其他';
                    break;
                default:
                    $nationality = '1汉族';
            }
            $list[$key]['ethnicityEnum'] = empty($value['nationality'])?'1汉族':$nationality;  //民族
            $list[$key]['address'] = empty($value['mailing_address'])?'待补录_通信地址':Security::decrypt($value['mailing_address']);  //通信地址
//            $list[$key]['householdIssueAuthority'] = $cityName?$cityName.'市级公安局':'无数据'; //户口登记机关名称
            $list[$key]['householdIssueAuthority'] = empty($value['household_issue_authority'])?($cityName?$cityName.'市级公安局':'无数据'):Security::decrypt($value['household_issue_authority']); //户口登记机关名称
            $list[$key]['permanentAddress'] = empty($value['permanent_address'])?'待补录_户口住址或常住地址':Security::decrypt($value['permanent_address']); //户口住址或常住地址
            $list[$key]['wyc_licenseNo'] = empty($value['qualifications_number'])?'待补录_资格证号':Security::decrypt($value['qualifications_number']);  //资格证号
//            $list[$key]['wyc_issueAuthority'] = $cityName?$cityName.'交通运输局':'无数据';  //发证机构
            $list[$key]['wyc_issueAuthority'] = empty($value['issue_agency'])?($cityName?$cityName.'交通运输局':'无数据'):Security::decrypt($value['issue_agency']);  //发证机构
            $list[$key]['wyc_firstIssueDate'] = empty($value['first_receive_date'])?'待补录_初次领取资格证日期':Security::decrypt($value['first_receive_date']);  //初次领取资格证日期
            $list[$key]['wyc_issueDate'] = empty($value['issue_date'])?'待补录_发证日期':Security::decrypt($value['issue_date']);  //发证日期
            $list[$key]['wyc_effectiveDate'] = empty($value['certificate_valid_start'])?'待补录_资格证有效起始日期':Security::decrypt($value['certificate_valid_start']);  //资格证有效起始日期
            $list[$key]['wyc_expiryDate'] = empty($value['certificate_valid_end'])?'待补录_资格证有效截止日期':Security::decrypt($value['certificate_valid_end']);  //资格证有效截止日期
            $list[$key]['wyc_registerDate'] = empty($value['register_date'])?'待补录_报备日期':Security::decrypt($value['register_date']);  //报备日期

            switch($value['wyc_service_type_enum']) { //经营范围
                case 1 :
                    $list[$key]['wyc_serviceTypeEnum'] = "3私人小客车合乘"; //对应 约约 私人小客车合乘
                    break;
                case 2 :
                    $list[$key]['wyc_serviceTypeEnum'] = "2巡游出租汽车";
                    break;
                case 3 :
                    $list[$key]['wyc_serviceTypeEnum'] = "1网约预约出租车";
                    break;
                default:
                    $list[$key]['wyc_serviceTypeEnum'] = '1网约预约出租车';
            }

            if ($value['wyc_is_taxi_driver_enum'] === 0) { //是否巡游出租车驾驶员
                $list[$key]['wyc_isTaxiDriverEnum'] = "0否";
            } else {
                $list[$key]['wyc_isTaxiDriverEnum'] = "1是";
            }

            if ($value['wyc_is_full_time_enum'] === 0 ) { //是否专职驾驶员
                $list[$key]['wyc_isFullTimeEnum'] = "0否";
            } else {
                $list[$key]['wyc_isFullTimeEnum'] = "1是";
            }

            $franchisee_info = [];
            if ($value['franchisee_type'] == 4) {
                if (!empty($value['franchisee_id'])) {
                    $db2 = Db::connect('db2');
                    $franchisee_info = $db2->table('franchisee')->field('name')->where('id', $value['franchisee_id'])->find();
                }
            }
//            $list[$key]['ht_company'] = empty($franchisee_info['name'])?'':$franchisee_info['name'];  //签署公司 用加盟商名称
            $list[$key]['ht_company'] = empty($value['sign_company'])?(empty($franchisee_info['name'])?'':$franchisee_info['name']):Security::decrypt($value['sign_company']);  //签署公司
//            $list[$key]['ht_effectiveDate'] = date('Y-m-d',$value['check_pass_time']);  //有效起始日期
            $list[$key]['ht_effectiveDate'] = empty($value['contract_valid_start'])?date('Y-m-d',$value['check_pass_time']):Security::decrypt($value['contract_valid_start']);  //有效起始日期
//            $list[$key]['ht_expiryDate'] = date('Y-m-d',$value['check_pass_time']+3*365*24*3600);  //有效截止日期
            $list[$key]['ht_expiryDate'] = empty($value['contract_valid_end'])?date('Y-m-d',$value['check_pass_time']+3*365*24*3600):Security::decrypt($value['contract_valid_end']);  //有效截止日期

//            $list[$key]['lxr_name'] = empty($value['driver_name'])?'待补录_联系人姓名':$value['driver_name'];  //联系人姓名
            $list[$key]['lxr_name'] = empty($value['lxr_name'])?$value['driver_name']:Security::decrypt($value['lxr_name']);  //联系人姓名
//            $list[$key]['lxr_phone'] = empty($value['driver_phone'])?'待补录_联系人电话':Security::decrypt($value['driver_phone']);  //联系人电话
            $list[$key]['lxr_phone'] = empty($value['lxr_phone'])?Security::decrypt($value['driver_phone']):Security::decrypt($value['lxr_phone']);  //联系人电话
            $list[$key]['lxr_address'] = empty($value['lxr_address'])?'待补录_联系人地址':Security::decrypt($value['lxr_address']); //联系人地址

            //司机培训信息
            $list[$key]['px_trainingName'] = empty($value['courseName'])?'小马出行司机培训':$value['courseName'];  //培训名称
//            $list[$key]['px_startTime'] = date('Y-m-d',$value['check_pass_time']);  //培训开始日期
            $list[$key]['px_startTime'] = empty($value['courseStartDate'])?date('Y-m-d',$value['check_pass_time']):date('Y-m-d',strtotime($value['courseStartDate']));  //培训开始日期
//            $list[$key]['px_endTime'] = date('Y-m-d',$value['check_pass_time']);  //培训结束日期
            $list[$key]['px_endTime'] = empty($value['courseEndDate'])?date('Y-m-d',$value['check_pass_time']):date('Y-m-d',strtotime($value['courseEndDate']));  //培训结束日期
//            $list[$key]['px_trainingHours'] = 6;  //培训时长
            $list[$key]['px_trainingHours'] = empty($value['courseDays'])?6:$value['courseDays'];  //培训时长 小时
            $list[$key]['px_isPassEnum'] = 1;  //培训是否通过 0否 1是
            $list[$key]['testGroupEnum'] = 0;  //是否推送监管 0推 1不推

            $list[$key]['surname'] = mb_substr($value['driver_name'], 0, 1);
            $list[$key]['name'] = mb_substr($value['driver_name'], 1);
            $list[$key]['id_number'] = Security::decrypt($value['id_number'])." ";
            $list[$key]['license_number'] = Security::decrypt($value['license_number'])." ";

        }

        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $list
        );
    }

    //约约车辆导出信息
    public function getCarListyy($page, $limit, $data = array(), $export = '')
    {
        $where = [];
        if (!empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['between', [strtotime($data['start']), strtotime($data['end'] . " 23:59:59")]];
        } elseif (!empty($data['start']) && empty($data['end'])) {
            $timeWhere = ['>=', strtotime($data['start'])];
        } elseif (empty($data['start']) && !empty($data['end'])) {
            $timeWhere = ['<=', strtotime($data['end'] . " 23:59:59")];
        }
        //注册时间
        if (!empty($data['type']) && $data['type'] == 1 && !empty($timeWhere)) {
            $where['register_time'] = $timeWhere;
        }
        //司机状态搜索
        //查询该司机是否在白名单 - 测试名单内
        $whiteList = Db::name('white_list')->order('id desc')->find();
        if (!empty($data['all_phone'])) {
            if ($data['all_phone'] == 1 && !empty($whiteList['driver_str'])) {        //正式司机
                $where['a.driver_id'] = ['not in', $whiteList['driver_str']];
            } elseif ($data['all_phone'] == 2 && !empty($whiteList['driver_str'])) {   //测试司机
                $where['a.driver_id'] = ['in', $whiteList['driver_str']];
            }
        }
        //登录时间
        if (!empty($data['type']) && $data['type'] == 2 && !empty($timeWhere)) {
            $where['last_login_time'] = $timeWhere;
        }

        //认证状态
        if ($data['auth_status'] != '') {
            $where['a.auth_status'] = $data['auth_status'];
        }
        //标签状态
        if (!empty($data['compliance_type'])) {
            $where['a.compliance_type'] = $data['compliance_type'];
        }
        //手机号码
        if ($data['driver_phone'] != '') {
            $where['a.driver_phone'] = Security::encrypt($data['driver_phone']);
        }
        //合规状态搜索
        if (!empty($data['confor_status'])) {
            $where['c.taxi_pass'] = $data['confor_status'];
            $where['c.taxi_certificate_pass'] = $data['confor_status'];
            $where['c.comm_pass'] = $data['confor_status'];
            $where['c.sail_pass'] = $data['confor_status'];
            $where['c.carriage_pass'] = $data['confor_status'];
        }
        //认证省市
        if (!empty($data['work_city'])) {
            $where['c.work_city'] = $data['work_city'];;
        }
        if ($data['referee_type'] != '') {
            if ($data['referee_type'] == 4) {
                $where['a.franchisee_type'] = 4;
            } elseif ($data['referee_type'] == 5) {
                $where['a.franchisee_type'] = 5;
            } else {
                $where['a.referee_type'] = $data['referee_type'];
            }
        }

        if (session('admin_type') == 5 && session('franchisee_str') != '') {
            $where['a.franchisee_id'] = ['in', session('franchisee_str')];
        } else {
            if ($data['franchisee_info'] != '') {
                $where['a.franchisee_id'] = $data['franchisee_info'];
            }
        }
        //司机类型
        if (!empty($data['driver_type'])) {
            $where['a.driver_type'] = $data['driver_type'];
        }
//        //标签信息
//        $complianceInfo = config('compliance');
//        //分页
//        $start = ($page - 1) * $limit;

        $list = Db::name('driver_base a')
            ->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')
            ->join('car_info c', 'a.driver_id = c.driver_id', 'LEFT')
            ->join('car_info_supplement s','s.car_id = c.car_id', 'LEFT')
            ->join('moreq_clbx bx','bx.car_id = c.car_id', 'LEFT')
            ->page($page, $limit)
            ->where($where)
            ->field('c.*,s.energy_type,s.car_type,s.plate_color,s.engine_id,s.vin as supplement_vin,s.transport_number,s.issuing_agency,s.manage_area,s.valid_start,s.valid_end,s.first_register_date,s.register_date,bx.*')
            ->order('a.driver_id desc')
            ->select();

        $count = Db::name('driver_base a')
            ->join('driver_info b', 'a.driver_id = b.driver_id', 'LEFT')
            ->join('car_info c', 'a.driver_id = c.driver_id', 'LEFT')
            ->join('car_info_supplement s','s.car_id = c.car_id', 'LEFT')
            ->join('moreq_clbx bx','bx.car_id = c.car_id', 'LEFT')
            ->where($where)
            ->count();
        foreach ($list as $key => $value) {
            $list[$key]['city'] = Db::name('region')->where('region_id', $value['work_city'])->value('region_name');
            $list[$key]['plateNoFirst'] = mb_substr(Security::decrypt($value['car_plate']), 0, 1);
            $list[$key]['car_plate'] = mb_substr(Security::decrypt($value['car_plate']),1);
            $list[$key]['brand'] = Security::decrypt($value['car_brand']);
            $list[$key]['color'] = Security::decrypt($value['color']);
            $list[$key]['vin'] = Security::decrypt($value['vin']);  // 车架号
            $list[$key]['car_vin'] = Security::decrypt($value['car_vin']); //车辆识别代码（17位字母+数字） 俗称 vin码
            switch ($list[$key]['color']) {
                case "黑色":
                    $list[$key]['color'] = "1" . $list[$key]['color'];
                    break;
                case "白色":
                    $list[$key]['color'] = "2" . $list[$key]['color'];
                    break;
                case "红色":
                    $list[$key]['color'] = "3" . $list[$key]['color'];
                    break;
                case "银色":
                    $list[$key]['color'] = "4" . $list[$key]['color'];
                    break;
                case "蓝色":
                    $list[$key]['color'] = "5" . $list[$key]['color'];
                    break;
                case "棕色":
                    $list[$key]['color'] = "6" . $list[$key]['color'];
                    break;
                case "绿色":
                    $list[$key]['color'] = "7" . $list[$key]['color'];
                    break;
                case "灰色":
                    $list[$key]['color'] = "8" . $list[$key]['color'];
                    break;
                case "黄色":
                    $list[$key]['color'] = "9" . $list[$key]['color'];
                    break;
                case "橙色":
                    $list[$key]['color'] = "10" . $list[$key]['color'];
                    break;
                case "粉色":
                    $list[$key]['color'] = "11" . $list[$key]['color'];
                    break;
                default:
                    $list[$key]['color'] = "100其它";
                    break;
            }
            $list[$key]['owner'] = Security::decrypt($value['owner']);
            if (strstr($list[$key]['brand'], '-')) {
                $list[$key]['brand'] = strstr($list[$key]['brand'], '-', true);
                $list[$key]['model'] = strstr(Security::decrypt($value['car_brand']), '-');
                $list[$key]['model'] = mb_substr($list[$key]['model'], 1);
            }
            $list[$key]['levelIdEnum'] = '1A级车';

            if ($value['register_at']) {
                $list[$key]['register_at'] = date('Y-m-d', $value['register_at']);
            } else {
                $list[$key]['register_at'] = "";
            }

            //能源类型  车牌号5位默认1汽油；车牌号6位默认3电(以电能驱动的汽车)
            $car_plate_res = strlen(mb_substr(Security::decrypt($value['car_plate']),2));
            if($car_plate_res == 6) {
                $list[$key]['energyTypeEnum'] = '3电(以电能驱动的汽车)';
                $list[$key]['plateColorEnum'] = '5绿色';
            } else {
                $list[$key]['energyTypeEnum'] = '1汽油';
                $list[$key]['plateColorEnum'] = '1蓝色';
            }
            $list[$key]['vehicleTypeEnum'] = '2小型汽车';  //车辆类型
            //车辆补录
//            $list[$key]['energyTypeEnum'] = empty($value['energy_type'])?'待补录_能源类型':Security::decrypt($value['energy_type']); //能源类型
//            $list[$key]['vehicleTypeEnum'] = empty($value['car_type'])?'待补录':Security::decrypt($value['car_type']); //车辆类型
//            $list[$key]['plateColorEnum'] = empty($value['plate_color'])?'待补录':Security::decrypt($value['plate_color']); //车牌颜色
//            $list[$key]['engine_id'] = empty($value['engine_id'])?'待补录':Security::decrypt($value['engine_id']); //发动机号
//            $list[$key]['vin'] = empty($value['car_vin'])?(empty($value['supplement_vin'])?'待补录':Security::decrypt($value['supplement_vin'])):Security::decrypt($value['vin']); //车辆vin
            $list[$key]['ysz_licenceNo'] = empty($value['transport_number'])?'待补录':Security::decrypt($value['transport_number']); //运输证号
            $list[$key]['ysz_issueAuthority'] = empty($value['issuing_agency'])?'待补录':Security::decrypt($value['issuing_agency']); //发证机构
            $list[$key]['ysz_bizScope'] = empty($value['manage_area'])?'待补录':Security::decrypt($value['manage_area']); //经营范围
            $list[$key]['ysz_effectiveDate'] = empty($value['valid_start'])?'待补录':Security::decrypt($value['valid_start']); //运输证有效期起
            $list[$key]['ysz_expiryDate'] = empty($value['valid_end'])?'待补录':Security::decrypt($value['valid_end']); //运输证有效期止
            $list[$key]['ysz_firstIssueDate'] = empty($value['first_register_date'])?'待补录':Security::decrypt($value['first_register_date']); //首次登记日期
            $list[$key]['ysz_registerDate'] = empty($value['valid_end'])?'待补录':Security::decrypt($value['valid_end']); //报备日期
            switch($value['service_type']) { //服务类型
                case 1 :
                    $list[$key]['ysz_serviceTypeEnum'] = "3私人小客车合乘"; //对应 约约 私人小客车合乘
                    break;
                case 2 :
                    $list[$key]['ysz_serviceTypeEnum'] = "2巡游出租汽车";
                    break;
                case 3 :
                    $list[$key]['ysz_serviceTypeEnum'] = "1网约预约出租车";
                    break;
                default:
                    $list[$key]['ysz_serviceTypeEnum'] = '1网约预约出租车';
            }

            $list[$key]['bx_company'] = empty($value['insuranceCompany'])?'待补录':$value['insuranceCompany']; //保险公司
            $list[$key]['bx_safetyNo'] = empty($value['insuranceCode'])?'待补录':$value['insuranceCode']; //保险号
            $list[$key]['bx_type'] = empty($value['insuranceType'])?'待补录':$value['insuranceType']; //保险类型
            $list[$key]['bx_price'] = empty($value['insuranceAmount'])?'待补录':$value['insuranceAmount']; //保险金额
            $list[$key]['bx_startDate'] = empty($value['insuranceValidDate'])?'待补录':$value['insuranceValidDate']; //保险生效日期
            $list[$key]['bx_endDate'] = empty($value['insuranceEndDate'])?'待补录':$value['insuranceEndDate']; //保险到期日期
            $list[$key]['dj_engineModel'] = empty($value['engine_type'])?'待补录':Security::decrypt($value['engine_type']); //发动机型号
            $list[$key]['dj_carCap'] = empty($value['engine_capacity'])?'2000':Security::decrypt($value['engine_capacity']);  //排量(ML)

            switch($value['inspection_status']) { //车辆检修状态
                case 0 :
                    $list[$key]['ext_overhaulStateEnum'] = '0未检修';
                    break;
                case 1 :
                    $list[$key]['ext_overhaulStateEnum'] = '1已检修';
                    break;
                default:
                    $list[$key]['ext_overhaulStateEnum'] = '1已检修';
            }
            $list[$key]['ext_nextOverhaulDate'] = empty($value['next_annual_inspection_time'])?date('Y-m-d',$value['auth_time']+365*24*3600):Security::decrypt($value['next_annual_inspection_time']); //下次年检时间
            switch($value['annual_review_status']) { //年审状态
                case 0 :
                    $list[$key]['ext_checkStateEnum'] = '0年审';
                    break;
                case 1 :
                    $list[$key]['ext_checkStateEnum'] = '1年审合格';
                    break;
                default:
                    $list[$key]['ext_checkStateEnum'] = '1年审合格';
            }
            $list[$key]['ext_printerSerialNo'] = empty($value['fee_print_id'])?'待补录':Security::decrypt($value['fee_print_id']); //发票打印序列号
            $list[$key]['ext_gpsBrand'] = empty($value['gps_brand'])?'待补录':Security::decrypt($value['gps_brand']); //gps品牌
            $list[$key]['ext_gpsModel'] = empty($value['gps_model'])?'待补录':Security::decrypt($value['gps_model']); //gps型号
            $list[$key]['ext_gpsImei'] = empty($value['imei_number'])?'待补录':Security::decrypt($value['imei_number']); //gps IMEI号
            $list[$key]['ext_gpsInstallDate'] = empty($value['install_date'])?'待补录':Security::decrypt($value['install_date']); //gps安装日期
        }
        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $list
        );
    }

}
